﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsCallback)
        {
            mvMedicineList.SetActiveView(vPatient);
            //gvStationare.DataBind();
        }
    }

    protected void lbtnBackToList_Click(object sender, EventArgs e)
    {     
        ddlPatients.DataBind();
        mvMedicineList.SetActiveView(vPatient);
    }

    protected  void ReBind()
    {
        ddlPatients.DataBind();
    }

    protected void ddlPatients_SelectedIndexChanged(object sender, EventArgs e)
    {
        mvMedicineList.SetActiveView(vMedicineList);
        gvStationare.PageIndex = 0;
        gvClinicDiagnose.PageIndex = 0;
    }

    protected void lbtnCancel_Click(object sender, EventArgs e)
    {
        mvMedicineList.SetActiveView(vMedicineList);
        dvMedicineList.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void lbtnUpdate_Click(object sender, EventArgs e)
    {
        dvMedicineList.UpdateItem(true);
        dvMedicineList.DataBind();
        mvMedicineList.SetActiveView(vMedicineList);
        dvMedicineList.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void dvStationare_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        string command = e.CommandName;

        switch (command)
        {
            case "Insert":
                mvMedicineList.SetActiveView(vMedicineList);               
                break;
            case "Cancel":
                mvMedicineList.SetActiveView(vPatient);
                dvStationare.ChangeMode(DetailsViewMode.ReadOnly);
                ReBind();
                break;
            case "Update":
                mvMedicineList.SetActiveView(vMedicineList);
                break;
            default: break;
        }
    }

    protected void gvStationare_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        mvMedicineList.SetActiveView(vMedicineList);

        string command = e.CommandName;

        switch (command)
        {
            case "Select":
                dvStationare.ChangeMode(DetailsViewMode.Edit);
                break;
            default: break;
        }
    }

    protected void dvClinicDiagnose_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        string command = e.CommandName;

        switch (command)
        {
            case "Insert":
                mvMedicineList.SetActiveView(vMedicineList);
                break;
            case "Cancel":
                mvMedicineList.SetActiveView(vPatient);
                dvClinicDiagnose.ChangeMode(DetailsViewMode.ReadOnly);
                ReBind();
                break;
            case "Update":
                mvMedicineList.SetActiveView(vMedicineList);
                break;
            default: break;
        }
    }

    protected void gvClinicDiagnose_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        mvMedicineList.SetActiveView(vMedicineList);

        string command = e.CommandName;

        switch (command)
        {
            case "Select":
                dvClinicDiagnose.ChangeMode(DetailsViewMode.Edit);
                break;
            default: break;
        }
    }

    protected void dvStationare_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        gvStationare.DataBind();
    }

    protected void dvClinicDiagnose_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        gvClinicDiagnose.DataBind();
    }

    protected void dvStationare_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        gvStationare.DataBind();
    }

    protected void dvClinicDiagnose_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        gvClinicDiagnose.DataBind();
    }

    protected void btnReminderDate_Click(object sender, EventArgs e)
    {
        
        sdsReminder.Insert();
        txtReminderDate.Text = string.Empty;
        mvMedicineList.SetActiveView(vMedicineList);
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //sdsSearchPatients.Select();
        //gvSearchResults.DataBind();
    }
}
